<template>
  <el-dialog :title="formData.id?'编辑页面':'增加页面'" :visible="showDialog" @close="closeFn">
    <el-form ref="form" :model="formData" :rules="rules" label-width="120px">
      <el-form-item label="标题名称" prop="title">
        <el-input v-model="formData.title" />
      </el-form-item>
      <el-form-item label="页面内容" prop="content">
        <quill-editor v-model="formData.content" @blur="$refs.form.validateField('content')" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-row type="flex" justify="center">
        <el-button size="small" type="primary" @click="submit">确定</el-button>
        <el-button size="small" @click="closeFn">取消</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formData: {
        title: '',
        content: '',
        created_at: '',
        id: '',
        updated_at: ''

      },
      rules: {
        title: [{ required: true, message: '标题名称不能为空', trigger: 'blur' }],
        content: [{ required: true, message: '内容不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    closeFn() {
      this.$emit('update:showDialog', false)
      this.formData = {
        title: '',
        content: '',
        created_at: '',
        id: '',
        updated_at: ''

      }
      this.$refs.form.resetFields()
    },
    async submit() {
      await this.$refs.form.validate()
      if (this.formData.id) {
        this.$emit('updatePages', this.formData)
      } else {
        this.$emit('addPages', this.formData)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
